package com.rs.lc.pm.model.user;

import com.rs.lc.pm.constans.RoleEnum;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Xavier_Wei on 2016/11/14.
 */
public class User implements Serializable {
    private long id;
    private String name;
    private String phone;
    private String password;
    private String avatar;
    private String email;

    private String role;

    private List<RoleEnum> roles;

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getAvatar() {
        return avatar;
    }

    public void setAvatar(String avatar) {
        this.avatar = avatar;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getRole() {
        return role;
    }

    public void setRole(String role) {
        this.role = role;
    }

    public List<RoleEnum> getRoles() {
        List<RoleEnum> res = new ArrayList<>();
        if (StringUtils.isNotBlank(role)) {
            String[] rs = role.split(",");
            for (String rss : rs) {
                RoleEnum e = RoleEnum.getByName(rss);
                if (e != null) res.add(e);
            }
        }
        return res;
    }

    @Override
    public String toString() {
        return "User{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", phone='" + phone + '\'' +
                ", password='" + password + '\'' +
                ", avatar='" + avatar + '\'' +
                ", email='" + email + '\'' +
                ", role=" + role +
                '}';
    }
}
